package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ai.ChatMessage;
import com.ruoyi.system.utils.BailianUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * AI助手控制器
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/ai")
public class SysAiController extends BaseController {
    @Autowired
    private BailianUtils bailianUtils;

    /**
     * 发送消息到AI助手
     */
    @PreAuthorize("@ss.hasPermi('system:ai:query')")
    @Log(title = "AI助手", businessType = BusinessType.OTHER)
    @PostMapping("/chat")
    public AjaxResult chat(@RequestBody ChatMessage message) {
        String response = bailianUtils.sendMessage(message.getContent());
        
        ChatMessage responseMessage = new ChatMessage();
        responseMessage.setContent(response);
        responseMessage.setRole("assistant");
        responseMessage.setTimestamp(System.currentTimeMillis());
        
        return success(responseMessage);
    }
} 